home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / jwpsrc.zip / JWP.H < prev    next >
C/C++ Source or Header  |  1993-03-28  |  26KB  |  598 lines

  1. /* Copyright (C) Stephen Chung, 1991-1992.  All rights reserved. */
  2.  
  3. #include <windows.h>
  4. #include "toolbar.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <mem.h>
  9. #include <dos.h>
  10. #include <io.h>
  11. #include <time.h>
  12.  
  13.  
  14. #define CTL3D           /* 3D Dialog Boxes */
  15.  
  16. /* Macros */
  17.  
  18. #define KANJI           unsigned short int
  19.  
  20. #define MAGIC           0x42022667L
  21.  
  22. #define JWPFILEVERSION  "B2"
  23.  
  24. #define NRSUMMARIES     5
  25. #define NRHEADERS       3
  26.  
  27. #define MAXLINELEN      512                 /* General length of a line */
  28. #define MAXFILENAMELEN  120                 /* General length of filenames */
  29. #define BUFSIZE         1024                /* General buffer for things */
  30. #define TEXTBLOCKSIZE   256                 /* One unit of text */
  31. #define UNDOTEXTSIZE    16                  /* One unit of undo text */
  32. #define MAXFILES        10                  /* Maximum number of files opened */
  33. #define MAXGLOSSARY     500                 /* Maximum number of glossaries */
  34. #define PROGNAME        "JWP"               /* Name of the program */
  35. #define NAMELEN         40                  /* General length for names */
  36. #define BLOCKSIZE       10240L              /* Optimal memory page size */
  37. #define C64K            (60L * 1024L)       /* 64K Blocks */
  38. #define CPOSPAGESIZE    BLOCKSIZE           /* Page size for the CPOS array */
  39.  
  40. #define BADKANJI        0x2223              /* Black square */
  41.  
  42. #define ISASCII(x)      ((HIBYTE(x) & 0x7f) == 0)
  43. #define ISKANJI(x)      ((HIBYTE(x) & 0x7f) != 0)
  44. #define KANJIAT(x,y)    ISKANJI(CHAROF(x,y))
  45. #define KANJIPOS(x)     KANJIAT(x,POSOF(x))
  46.  
  47. #define BASEFONT        (global.basefont)
  48. #define PRINTFONT       (global.printfont)
  49. #define SYSFONT         (global.sysfont)
  50.  
  51. #define LINEGAP(x)      ((x)->spacing / 2)
  52. #define CHARGAP(x)      ((x)->leading / 2)
  53.  
  54. #define BlockAlloc(x)   SegHeapAlloc(x)
  55. #define BlockRealloc(x, n) SegHeapRealloc(x, n)
  56. #define FreeBlock(x)    SegHeapFree(x)
  57.  
  58. #define StructAlloc(x)  ((x far *) SegHeapAlloc(sizeof(x)))
  59. #define FreeStruct(x)   SegHeapFree(x)
  60.  
  61. #define MemAlloc(x)     MyLocalAlloc(x)
  62. #define FreeMem(x)      LocalFree(x)
  63.  
  64. #define PARAOF(x)       ((x).para)
  65. #define LINEOF(x)       ((x).line)
  66. #define POSOF(x)        ((x).pos)
  67. #define UNITOF(x,y)     (PARAOF(x)->text[LINEOF(x)->position + y])
  68. #define CHAROF(x,y)     UNITOF(x,y).kanji
  69. #define FORMATOF(x,y)   UNITOF(x,y).format
  70. #define POS2ABS(x)      (LINEOF(x)->position + POSOF(x))
  71.  
  72. #define TOPPARA(x)      PARAOF((x)->top)
  73. #define TOPLINE(x)      LINEOF((x)->top)
  74. #define CURPARA(x)      PARAOF((x)->current)
  75. #define CURLINE(x)      LINEOF((x)->current)
  76. #define CURCHAR(x)      POSOF((x)->current)
  77.  
  78. #define CURX(f)         ((f)->cursor.x)
  79. #define CURY(f)         ((f)->cursor.y)
  80. #define PSEUDOX(f)      ((f)->pseudo.x)
  81. #define PSEUDOY(f)      ((f)->pseudo.y)
  82.  
  83. #define SELNOW(x)       ((x)->sel.now)
  84. #define SEL1(x)         ((x)->sel.pos1)
  85. #define SEL2(x)         ((x)->sel.pos2)
  86. #define SELPARA1(x)     PARAOF(SEL1(x))
  87. #define SELPARA2(x)     PARAOF(SEL2(x))
  88. #define SELPOS1(x)      POSOF((x)->sel.pos1)
  89. #define SELPOS2(x)      POSOF((x)->sel.pos2)
  90. #define SELCHAR1(x)     (SELPARA1(x)->text[SELPOS1(x)])
  91. #define SELCHAR2(x)     (SELPARA2(x)->text[SELPOS2(x)])
  92. #define SELTYPE(x)      ((x)->sel.type)
  93.  
  94. #define RULER(x)        ((x)->ruler)
  95. #define BASEWIDTH(x)    ((x)->basefont->width + (x)->leading)
  96.  
  97. #define RULERHEIGHT     (2 * AVGHEIGHT)
  98. #define BORDERSPACE     (global.borderspace)
  99. #define AVGWIDTH        (global.textmetric.tmAveCharWidth)
  100. #define AVGHEIGHT       (global.textmetric.tmHeight + global.textmetric.tmExternalLeading)
  101.  
  102. #define STATUSHEIGHT    (AVGHEIGHT * 1.3)
  103.  
  104. #define TBBORDER        6
  105. #define TBICONHEIGHT    24
  106. #define TBICONWIDTH     24
  107. #define TBHEIGHT        (TBICONHEIGHT + 2 * BORDERSPACE)
  108.  
  109. #define POS2PIXEL(x)    (BORDERSPACE + (x) * BASEWIDTH(f) - f->startx)
  110. #define LEFTMARGIN(x)   ((LINEOF(x)->prev == NULL) ? PARAOF(x)->firstindent : PARAOF(x)->leftindent)
  111. #define NEXTLINE(x)     Skip(&(x), 1)
  112. #define PREVLINE(x)     Skip(&(x), -1)
  113.  
  114.  
  115.  
  116. /* Type definitions */
  117.  
  118. #define OP_MOVESEL          0x0001          /* Options for ReformatParagraph */
  119. #define OP_UPDATE           0x0002
  120. #define OP_MOVETOEND        0x0004
  121. #define OP_REFORMAT         0x0008
  122. #define OP_SAMELEN          0x0010
  123. #define OP_MINIMAL          0x0020
  124. #define OP_WITHFORMAT       0x0040
  125. #define OP_CHOOSEKANJI      0x0080
  126.  
  127. #define FN_NORMAL           0x0001          /* Normal file */
  128. #define FN_CLIPBOARD        0x0002          /* Clipboard */
  129. #define FN_CONTROL          0x0004          /* A Japanese edit control */
  130. #define FN_NOSWITCHING      0x0008          /* No mode switching at all times */
  131. #define FN_EITHER           0x0010          /* Either ASCII or Japanese */
  132. #define FN_NOKANJI          0x0020          /* No Kanji allowed */
  133. #define FN_NOEDIT            0x0040            /* No editing allowed */
  134. #define FN_NOSCROLLBARS        0x0080            /* Do not display scrollbars */
  135.  
  136.  
  137. typedef enum { SEL_CONVERSION, SEL_SELECTION } SELTYPE;
  138.  
  139. typedef enum { M_KANA, M_ASCII } INPUTMODE;
  140.  
  141. typedef enum {
  142.     UN_INSERT, UN_DELETE, UN_INDENT, UN_SPLITLINE, UN_JOINLINE
  143. } EDITACTION;
  144.  
  145. typedef enum {
  146.     J_LEFT, J_RIGHT, J_CENTER, J_JUSTIFY
  147. } JUSTIFICATION;
  148.  
  149. typedef enum {
  150.     U_INSERT, U_DELETE, U_REPLACE, U_PARAFORMAT
  151. } UNDOACTIONS;
  152.  
  153. typedef enum {
  154.     M_INCHES =  0,
  155.     M_CM =      1,
  156.     M_MM =      2,
  157.     M_POINTS =  3,
  158.     M_PIXELS =  4
  159. } MEASUREMENT;
  160.  
  161. typedef struct {
  162.     char *name;
  163.     char *symbol;
  164.     int decimal;
  165.     double conversion;
  166. } MEASUREINFO;
  167.  
  168. typedef enum {
  169.     FF_UNKNOWN =  0,
  170.     FF_NORMAL =   1,
  171.     FF_TEMPLATE = 2,
  172.     FF_EUC =      3,
  173.     FF_SJIS =     4,
  174.     FF_NEWJIS =   5,
  175.     FF_OLDJIS =   6,
  176.     FF_NEC =      7
  177. } FILEFORMAT;
  178.  
  179.  
  180. typedef struct UndoBufStruct {
  181.     int para1, start;
  182.     int para2, stop;
  183.     time_t time;
  184.     UNDOACTIONS action;
  185.     KANJI far *data;
  186.     struct UndoBufStruct far *next, far *prev;
  187. } UNDOBUF;
  188.  
  189.  
  190. typedef struct {                    /* The header for JWP's native format */
  191.     unsigned long int magic;        /* Magic identifier */
  192.     char version[6];                /* Version number */
  193.     unsigned int paragraphs;        /* Number of paragraphs */
  194.     float margins[4];               /* Left/Right/Top/Bottom margins, in inches */
  195.  
  196.     int landscape:1;                /* Landscape printing */
  197.     int summary:1;                  /* File summary exists */
  198.     int headers:1;                  /* Has header / footer */
  199.     int lrheader:1;                 /* Separate Left/Right pages in header/footer? */
  200.     int nofirstpage:1;              /* Don't print header/footer on first page? */
  201.     unsigned int undo;              /* Number of undo levels */
  202.     char extra[97];                 /* Make it up to 128 bytes */
  203. } FILEHEADER;
  204.  
  205.  
  206. typedef struct {
  207.     unsigned int textsize;          /* Number of characters in this paragraph */
  208.     unsigned int firstindent;       /* Indentations */
  209.     unsigned int leftindent;
  210.     unsigned int rightindent;
  211. } OLDFILEPARAHEADER100;
  212.  
  213.  
  214. typedef struct {
  215.     unsigned int textsize;          /* Number of characters in this paragraph */
  216.     unsigned int spacemulti;        /* Spacing, x 100 */
  217.     unsigned char firstindent;      /* Indentations */
  218.     unsigned char leftindent;
  219.     unsigned char rightindent;
  220.     unsigned char extra[9];         /* Pad it to 16 byte */
  221. } FILEPARAHEADER;
  222.  
  223.  
  224. typedef struct {
  225.     KANJI facename[NAMELEN/2];      /* Font family name */
  226.     int width, height;              /* Width and height in pixels */
  227.     int charsize;                   /* Number of bytes that make up a character */
  228.     int verticals;                  /* The number of extra "vertical" characters */
  229.     long int offset;                /* Byte offset to the beginning of bitmaps */
  230.     BOOL holes;                     /* Packed JIS coding or 93x93 with holes */
  231.     int leading, spacing;           /* Horizontal / Vertical gaps */
  232.     char extra[6];                  /* Make it up to 64 bytes */
  233. } FONTHEADER;
  234.  
  235.  
  236. typedef struct {